package com.bizmerce.rnd.oms.codemng.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.bizmerce.rnd.oms.codemng.service.FtaSearchVO;
import com.bizmerce.rnd.oms.codemng.service.FtaVO;

import egovframework.rte.psl.dataaccess.EgovAbstractDAO;

@SuppressWarnings("unchecked")
@Repository("ftaDAO")
public class FtaDAO extends EgovAbstractDAO {

	/**
	 * FTA협정관리 - 정보 가져오기
	 */
	public List<FtaVO> selectFtas(FtaSearchVO searchVO) {
		int skipResult = (searchVO.getPageIndex() - 1) * searchVO.getPageUnit();
		int maxResult = searchVO.getPageUnit();
		return getSqlMapClientTemplate().queryForList("CodeMng.selectFtas", skipResult, maxResult);
	}

	public int selectFtasCount() {
		return (Integer) getSqlMapClientTemplate().queryForObject("CodeMng.selectFtasCount");
	}
	/**
	 * FTA협정관리 - 적용
	 */
	public void apply(String id) {
		HashMap<String, String> param = new HashMap<String, String>();
		param.put("APPLYN", "Y");
		param.put("ACLT_APPLYN", "Y");
		param.put("AGREE_CD", id);
		getSqlMapClientTemplate().update("CodeMng.updateFtas", param);
	}

	/**
	 * FTA협정관리 - 미적용
	 * 
	 * @param id
	 */
	public void noApply(String id) {
		HashMap<String, String> param = new HashMap<String, String>();
		param.put("APPLYN", "N");
		param.put("ACLT_APPLYN", "N");
		param.put("AGREE_CD", id);
		getSqlMapClientTemplate().update("CodeMng.updateFtas",param);
	}

	/**
	 * FTA협정관리 - 협정내역 정보 가져오기
	 * 
	 * @param id
	 */
	public FtaVO selectFta(String id) {
		HashMap<String, String> param = new HashMap<String, String>();
		param.put("AGREE_CD", id);
		return (FtaVO) getSqlMapClientTemplate().queryForObject("CodeMng.selectFta", param);
	}

	/**
	 * FTA협정관리 - 협정내역 저장
	 * 
	 */
	public void updateFta(FtaVO fta) {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("AGREE_CD", fta.getId());
		param.put("AGREE_NM", fta.getName());
		param.put("EFFECTDATE", fta.getEffectiveDate());
		param.put("CERT_EXPTER_MANG_YN", fta.isCertificatedExporter());
		param.put("CERT_EXPTER_MANG_NUM", fta.getCertificatedExporterNo());
		param.put("CERTTYPE", fta.getCertificateType());
		param.put("CERTAVA_DATE", fta.getAvaiableDate());
		param.put("AGREENAT", fta.getPartners());
		param.put("APPLYN", fta.isApply());
		getSqlMapClientTemplate().update("CodeMng.updateFta", param);
	}
	
	/**
	 * 누적기준 적용여부
	 * @param id 
	 */
	public FtaVO selectCum(String id) {
		HashMap<String, String> param = new HashMap<String, String>();
		param.put("AGREE_CD", id);
		return (FtaVO) getSqlMapClientTemplate().queryForObject("CodeMng.selectCum",param);
	}

	/**
	 * 누적기준 -저장
	 * @param id 
	 */
	public void updateCum(String id, boolean apply)  {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("AGREE_CD", id);
		param.put("ACLT_APPLYN", apply);
		getSqlMapClientTemplate().update("CodeMng.updateCum", param);
	}
}